package com.dhemery.mack.actions;

import java.util.List;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;

//TODO Test this class
public class MenuFactory {
	public void fill(IContributionManager menu, ActionList actionList) {
		for(IAction action : actionList.getActions()) {
			menu.add(action);
		}
	}

	public void fillMenus(List<IContributionManager> menus, ActionSet actionSet) {
		for(IContributionManager menu : menus) {
			fillSections(menu, actionSet);
		}
	}

	public void fillSections(IContributionManager menu, ActionSet actionSet) {
		for(ActionList actionList : actionSet.getActionLists()) {
			fill(menu, actionList);
			menu.add(new Separator());
		}
	}

	public void makeMenu(IContributionManager menuBar, ActionList actionList) {
		IMenuManager menu = new MenuManager(actionList.getName());
		menuBar.add(menu);
		fill(menu, actionList);
	}

	public void makeMenus(IMenuManager menuBar, ActionSet actionSet) {
		for(ActionList actionList : actionSet.getActionLists()) {
			makeMenu(menuBar, actionList);
		}
	}

	public void makeToolBar(ICoolBarManager coolBar, ActionList actionList) {
		IToolBarManager toolBar = new ToolBarManager(coolBar.getStyle());
		coolBar.add(toolBar);
		fill(toolBar, actionList);
	}

	public void makeToolBars(ICoolBarManager coolBar, ActionSet actionSet) {
		for(ActionList actionList : actionSet.getActionLists()) {
			makeToolBar(coolBar, actionList);
		}
	}
}
